import subprocess
import sys
import os


def get_best_model_name(folder_suffix):
    # 获取目标文件夹下所有文件名称
    name_list = os.listdir(f"/home/jacy/GDW/data_{folder_suffix}/model")
    # 匹配前缀为"best"的文件名返回
    for name in name_list:
        if name.startswith("best"):
            return name


def main(args):
    # /home/jacy/anaconda3/envs/mmyolo/lib/python3.8/site-packages/mmdet/engine/hooks/visualization_hook.py
    #  可视化的 score_thr (float): The threshold to visualize the bboxes and masks. Defaults to 0.3.

    best_model = get_best_model_name(args[1])
    command = (
        f"python /home/jacy/PyPjs/detection/mmyolo/tools/test.py "
        f"/home/jacy/GDW/data_{args[1]}/yolov8_s_syncbn_fast_8xb16-500e_coco.py "
        f"/home/jacy/GDW/data_{args[1]}/model/{best_model} "
        f"--work-dir /home/jacy/GDW/data_{args[1]}/inference "
        f"--out /home/jacy/GDW/data_{args[1]}/inference/pending_result.pkl "
        f"--show-dir /home/jacy/GDW/data_{args[1]}/inference/images"
    )

    try:
        subprocess.run(command, shell=True, check=True)
    except subprocess.CalledProcessError as e:
        print(f"Error occurred: {e}")


if __name__ == '__main__':
    main(sys.argv)
